package ai.people.netmon.twitter.probe.controller;

import ai.people.netmon.framework.domain.twitter.probe.entity.TwitterAccount;
import ai.people.netmon.framework.domain.twitter.probe.request.UserWebRequest;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.netmon.twitter.probe.service.TwitterUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 探测-用户新接口
 *
 * @author yuanqinglong
 * @date 2022/2/25 10:36
 */
@Validated
@RestController
@RequestMapping("/probe/user")
public class TwitterUserController  {


    @Autowired
    private TwitterUserService twitterUserServiceImpl;


    /**
     * 获取用户
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("{id}")
    public Result<TwitterAccount> getUser(@PathVariable("id") Long id) {
        return ResultUtil.success(twitterUserServiceImpl.getUser(id));
    }


    /**
     * 保存用户
     *
     *
     * @param twitterCollectConfigAccount twitter配置账户
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> saveUser(@Validated @RequestBody TwitterAccount twitterCollectConfigAccount) {
        twitterUserServiceImpl.saveTwitterUser(twitterCollectConfigAccount);
        return ResultUtil.success();
    }


    /**
     * 批量保存用户
     *
     * @param twitterCollectConfigAccount twitter配置账户
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/batchSave")
    public Result<?> batchSaveUser(@RequestBody List<TwitterAccount> twitterCollectConfigAccount) {
        twitterUserServiceImpl.batchSaveTwitterUser(twitterCollectConfigAccount);
        return ResultUtil.success();
    }


    /**
     * 更新用户
     *
     * @param twitterCollectConfigAccount twitter配置账户
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping
    public Result<?> updateUser(@Validated @RequestBody TwitterAccount twitterCollectConfigAccount) {
        twitterUserServiceImpl.updateTwitterUser(twitterCollectConfigAccount);
        return ResultUtil.success();
    }


    /**
     * twitter账户列表
     *
     * @param userRequest 用户请求
     * @return {@link Result}<{@link PageResponse}<{@link TwitterAccount}>>
     */ 
    @PostMapping("/list")
    public Result<PageResponse<TwitterAccount>> listTwitterAccounts(@RequestBody UserWebRequest userRequest) {
        PageResponse<TwitterAccount> twitterAccounts = twitterUserServiceImpl.listTwitterAccounts(userRequest);
        return ResultUtil.success(twitterAccounts);
    }


}
